@extends('admin.defaults.head')
@section('title','首页')
@section('body')

    {{--请在下面编辑body 内容--}}


    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <!-- 头部区域 -->
            <ul class="layui-nav layui-layout-left">
                <li class="layui-nav-item layadmin-flexible" lay-unselect lay-tips="侧边伸缩">
                    <a href="javascript:;" layadmin-event="flexible" >
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
                    </a>
                </li>
                <li class="layui-nav-item layui-hide-xs" lay-unselect lay-tips="新窗口打开前台首页">
                    <a href="{{$indexurl}}"  target="_blank" >
                        <i class="layui-icon layui-icon-find-fill"></i>
                    </a>
                </li>
                <li class="layui-nav-item layui-hide-xs" lay-unselect lay-tips="新窗口打开当前标签页">
                    <a href="javascript:;" onclick="window.open($('.layadmin-tabsbody-item.layui-show iframe').attr('src'))"  >
                        <i class="layui-icon layui-icon-link"></i>
                    </a>
                </li>
                <li class="layui-nav-item" lay-unselect lay-tips="刷新当前标签页">
                    <a href="javascript:;" layadmin-event="refresh"  >
                        <i class="layui-icon layui-icon-refresh-3"></i>
                    </a>
                </li>
                @if ($search['isshow'])
                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <input type="text" placeholder="搜索..." autocomplete="off" class="layui-input layui-input-search" layadmin-event="serach" lay-action="{{$search['url']}}?keywords=">
                </li>
                @endif
            </ul>
            <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">
                @if ($message['isshow'])
                <li class="layui-nav-item" lay-unselect lay-tips="{{$message['title']}}">
                    <a lay-href="{{$message['url']}}" layadmin-event="message" lay-text="{{$message['title']}}">
                        <i class="layui-icon layui-icon-notice"></i>

                        <!-- 如果有新消息，则显示小圆点 -->
                        <span class="layui-badge-dot"></span>
                    </a>
                </li>
                @endif
                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="theme">
                        <i class="layui-icon layui-icon-theme"></i>
                    </a>
                </li>
                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="note">
                        <i class="layui-icon layui-icon-note"></i>
                    </a>
                </li>
                <li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="fullscreen">
                        <i class="layui-icon layui-icon-screen-full"></i>
                    </a>
                </li>
                <li class="layui-nav-item" lay-unselect style="margin-right: 20px">
                    <a href="javascript:;">
                        <cite>{{$userdata->username}}({{$userdata->realname}})</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd onclick="editmyinfo()" style="text-align: center;"><a>基本资料</a></dd>
                        <dd onclick="editmypasswords()" style="text-align: center;"><a>修改密码</a></dd>
                        <hr>
                        <dd onclick="logout()" style="text-align: center;"><a>退出</a></dd>
                    </dl>
                </li>

                <!--<li class="layui-nav-item layui-hide-xs" lay-unselect>
                    <a href="javascript:;" layadmin-event="about"><i class="layui-icon layui-icon-more-vertical"></i></a>
                </li>
                <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-unselect>
                    <a href="javascript:;" layadmin-event="more"><i class="layui-icon layui-icon-more-vertical"></i></a>
                </li>-->
            </ul>
        </div>

        <!-- 侧边菜单 -->
        <div class="layui-side layui-side-menu">
            <div class="layui-side-scroll">
                <div class="layui-logo" lay-href="{$homeurl}" style="background: white !important">
                    <img src="{{$logo}}" height="100%" width="100%" alt="">
                    <span></span>
                </div>


                @php


                    function foreachmenus($menus,$index){
                    $index++;
                    if((!isset($menus['children']) || count($menus['children'])==0)){
                    $rest= ' <a lay-href="'.(isset($menus['rule'])?$menus['rule']:'').'"><i class="layui-icon '.(isset($menus['icon'])?$menus['icon']:'').' "></i><cite>'.(isset($menus['title'])?$menus['title']:'').'</cite></a>';
                    }else{

                    $rest='<a href="javascript:;"  lay-tips="'.(isset($menus['title'])?$menus['title']:'').'" lay-direction="2">';
                        $rest.='<i class="layui-icon '.(isset($menus['icon'])?$menus['icon']:'').'"></i>';
                        $rest.='<cite>'.(isset($menus['title'])?$menus['title']:'').'</cite></a><dl class="layui-nav-child">';

                        foreach ($menus['children'] as $key=>$menus1){
                        $index++;
                        $rest.='<dd data-name="menu'.$index.'" >';

                            $rest.=foreachmenus($menus1,$index);


                            $rest.='</dd>';
                        }


                        $rest.='</dl>';

                    }
                    return $rest;

                    }
                @endphp



                <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">
                    @php
                        $menusindex=1;

                    @endphp
                    @foreach($adminmenus as $index=>$menus)
                    <li data-name="menu{$menusindex}" class="layui-nav-item @if($index==0) layui-nav-itemed @endif">

                        @php
                            echo foreachmenus($menus,$menusindex);
                                $menusindex+=100;
                        @endphp

                    </li>
                    @endforeach









                </ul>
            </div>
        </div>

        <!-- 页面标签 -->
        <div class="layadmin-pagetabs" id="LAY_app_tabs">
            <div class="layui-icon layadmin-tabs-control layui-icon-prev" layadmin-event="leftPage"></div>
            <div class="layui-icon layadmin-tabs-control layui-icon-next" layadmin-event="rightPage"></div>
            <div class="layui-icon layadmin-tabs-control layui-icon-down">
                <ul class="layui-nav layadmin-tabs-select" lay-filter="layadmin-pagetabs-nav">
                    <li class="layui-nav-item" lay-unselect>
                        <a href="javascript:;"></a>
                        <dl class="layui-nav-child layui-anim-fadein">
                            <dd layadmin-event="closeThisTabs"><a href="javascript:;">关闭当前标签页</a></dd>
                            <dd layadmin-event="closeOtherTabs"><a href="javascript:;">关闭其它标签页</a></dd>
                            <dd layadmin-event="closeAllTabs"><a href="javascript:;">关闭全部标签页</a></dd>
                        </dl>
                    </li>
                </ul>
            </div>
            <div class="layui-tab" lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">
                <ul class="layui-tab-title" id="LAY_app_tabsheader">
                    <li lay-id="{{$homeurl}}" lay-attr="{{$homeurl}}" class="layui-this"><i class="layui-icon layui-icon-home"></i></li>
                </ul>
            </div>
        </div>


        <!-- 主体内容 -->
        <div class="layui-body" id="LAY_app_body">
            <div class="layadmin-tabsbody-item layui-show">
                <iframe src="{{$homeurl}}" frameborder="0" class="layadmin-iframe"></iframe>
            </div>
        </div>

        <!-- 辅助元素，一般用于移动设备下遮罩 -->
        <div class="layadmin-body-shade" layadmin-event="shade"></div>
    </div>
</div>



    {{--上方body内容结束   请在下面编辑script 内容--}}

    @endsection
    @section('script')
        <script>
            layui.config({
                base: '/style_js_admin/layuiadmin/' //静态资源所在路径
            }).extend({
                index: 'lib/index' //主入口模块
            }).use('index');
            function logout() {
                layer.confirm('确定要退出吗？', function(index) {
                    window.location.href="/admin/login";

                });
            }


          function editmypasswords(){
                layer.open({
                    type: 2
                    ,title: '修改密码'
                    ,content: '/admin/admin/editmypasswords'
                    ,area: ['420px', '320px']
                    ,maxmin: true
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-role-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+submitID+')', function(data){
                            var field = data.field; //获取提交的字段

                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url:'/admin/admin/editmypasswords',
                                type:'POST',
                                data:field,
                                success:function(result){
                                    layer.msg(result.message)
                                    if(result.code==200){
                                        setTimeout(function () {
                                            window.location.href="/admin/login";
                                        }, 2000);
                                    }

                                }});

                        });

                        submit.trigger('click');
                    }
                });
            };

            function editmyinfo(){
                layer.open({
                    type: 2
                    ,title: '修改我的信息'
                    ,content: '/admin/admin/editmyinfo?id={{$userdata->id}}'
                    ,area: ['420px', '620px']
                    ,maxmin: true
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-role-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+submitID+')', function(data){
                            var field = data.field; //获取提交的字段

                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url:'/admin/admin/editmyinfo',
                                type:'POST',
                                data:field,
                                success:function(result){
                                    layer.msg(result.message)
                                    if(result.code==200){
                                        layer.close(index); //关闭弹层
                                    }

                                }});

                        });

                        submit.trigger('click');
                    }
                });
            };
        </script>
    @endsection


